#include "Directory.h"
#include "File.h"

#include <Windows.h>

#include <set>
using std::set;
#include <list>
using std::list;
#include <string>
using std::wstring;
#include <map>
using std::map;
#include <queue>
using std::queue;
using std::pair;

// Class FileDuplicates
//   Provides searching of file duplicates in specified directory
//   
// Typical using:
//   1) Construct with given directory (see "Directory.h")
//   2) Check if is valid
//   3) Search
//   4) Get results
//   5) Perform some action (delete specified files)

struct FileWithDuplicates
  {
  File m_file;
  list<wstring> m_duplicates;
  };

class FileDuplicates
  {
  public:
    FileDuplicates(const Directory& i_directory);
    FileDuplicates(const wstring& i_dir_name);
    ~FileDuplicates();

    void Search();
    bool IsDone() const;
    map<wstring, list<wstring>> GetResult() const;
    size_t GetFailedToOpen() const;
    list<list<wstring>> GetDuplicates() const;

    pair<unsigned __int64, unsigned __int64> GetProgress() const;
  private:
    set<File> m_files;
    map<wstring, list<wstring>> m_duplicates;
    bool m_done;
    Directory m_directory;
    queue<Directory> m_scan_queue;
    size_t m_failed_to_open;
    
    unsigned __int64 m_bytes_done;
    unsigned __int64 m_bytes_todo;

    void _SearchNext();
  };
